package com.boil.qz.safekavass.model;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by ChenYong on 2017-04-11.
 * <br>
 * 后台用户实体类。
 */
@Entity
@Table(name = "TB_LOGIN_USERS")
public class LoginUser extends BaseEntity {
    /**
     * 序列化 ID
     */
    private static final long serialVersionUID = -8650521062520519831L;
    /**
     * 登录 ID
     */
    private String loginid;
    /**
     * 姓名
     */
    private String loginName;
    /**
     * 密码
     */
    private String pwd;
    /**
     * 所属行业代码
     */
    private String industryCode;
    /**
     * 是否为领导：0-否；1-是
     */
    private String isLeader;
    /**
     * 所属企业编码
     */
    private String collieryNo;
    /**
     * 所属安委会单位代码
     */
    private String secComUnitCode;
    /**
     * 所属安委会单位名称
     */
    @Transient
    private String secComUnitName;
    /**
     * 用户拥有的角色 <code>Set</code>
     */
    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
    @JoinTable(name = "TB_QZ_USER_ROLE", //
            joinColumns = @JoinColumn(name = "USER_ID"), //
            inverseJoinColumns = @JoinColumn(name = "ROLE_ID"))
    private Set<RoleEntity> roles;
    /**
     * 用户创建的首页广告 <code>Set</code>
     */
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "loginUser")
    private Set<HomeAdvert> homeAdverts;
    /**
     * 用户创建的通知 <code>Set</code>
     */
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "loginUser")
    private Set<Notice> notices;
    /**
     * 用户创建的学习动态 <code>Set</code>
     */
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "loginUser")
    private Set<LearnDym> learnDyms;
    /**
     * 用户创建的学习资料 <code>Set</code>
     */
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "loginUser")
    private Set<LearnFileData> learnFileData;

    // 普通初始化块
    {
        roles = new HashSet<RoleEntity>();
        homeAdverts = new HashSet<HomeAdvert>();
        notices = new HashSet<Notice>();
        learnDyms = new HashSet<LearnDym>();
        learnFileData = new HashSet<LearnFileData>();
    }

    /**
     * 默认构造器。
     */
    public LoginUser() {
        super();
    }

    public String getLoginid() {
        return loginid;
    }

    public void setLoginid(String loginid) {
        this.loginid = loginid;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getIndustryCode() {
        return industryCode;
    }

    public void setIndustryCode(String industryCode) {
        this.industryCode = industryCode;
    }

    public String getIsLeader() {
        return isLeader;
    }

    public void setIsLeader(String isLeader) {
        this.isLeader = isLeader;
    }

    public String getCollieryNo() {
        return collieryNo;
    }

    public void setCollieryNo(String collieryNo) {
        this.collieryNo = collieryNo;
    }

    public String getSecComUnitCode() {
        return secComUnitCode;
    }

    public void setSecComUnitCode(String secComUnitCode) {
        this.secComUnitCode = secComUnitCode;
    }

    public String getSecComUnitName() {
        return secComUnitName;
    }

    public void setSecComUnitName(String secComUnitName) {
        this.secComUnitName = secComUnitName;
    }

    public Set<RoleEntity> getRoles() {
        return roles;
    }

    public void setRoles(Set<RoleEntity> roles) {
        this.roles = roles;
    }

    public Set<HomeAdvert> getHomeAdverts() {
        return homeAdverts;
    }

    public void setHomeAdverts(Set<HomeAdvert> homeAdverts) {
        this.homeAdverts = homeAdverts;
    }

    public Set<Notice> getNotices() {
        return notices;
    }

    public void setNotices(Set<Notice> notices) {
        this.notices = notices;
    }

    public Set<LearnDym> getLearnDyms() {
        return learnDyms;
    }

    public void setLearnDyms(Set<LearnDym> learnDyms) {
        this.learnDyms = learnDyms;
    }

    public Set<LearnFileData> getLearnFileData() {
        return learnFileData;
    }

    public void setLearnFileData(Set<LearnFileData> learnFileData) {
        this.learnFileData = learnFileData;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("LoginUser{");
        sb.append("loginid='").append(loginid).append('\'');
        sb.append(", loginName='").append(loginName).append('\'');
        sb.append(", pwd='").append(pwd).append('\'');
        sb.append(", industryCode='").append(industryCode).append('\'');
        sb.append(", isLeader='").append(isLeader).append('\'');
        sb.append(", collieryNo='").append(collieryNo).append('\'');
        sb.append(", secComUnitCode='").append(secComUnitCode).append('\'');
        sb.append(", secComUnitName='").append(secComUnitName).append('\'');
        sb.append(", roles=").append(roles);
        sb.append(", homeAdverts=").append(homeAdverts);
        sb.append(", notices=").append(notices);
        sb.append(", learnDyms=").append(learnDyms);
        sb.append(", learnFileData=").append(learnFileData);
        sb.append(", id=").append(id);
        sb.append('}');
        return sb.toString();
    }
}